package com.wu.client.controller;

import com.wu.client.service.AlbumService;
import com.wu.client.vo.req.album.AlbumReq;
import com.wu.client.vo.res.album.AlbumBaseResp;
import com.wu.client.vo.res.album.AlbumDetailResp;
import com.wu.client.vo.res.PageResp;
import com.wu.common.convertion.result.Result;
import com.wu.common.convertion.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Cousin
 * @date 2025/3/5
 * @Description
 */
@RestController
@RequestMapping("albums")
@RequiredArgsConstructor
public class AlbumController {
    private final AlbumService albumService;

    @GetMapping("/{id}")
    public Result<AlbumDetailResp> getAlbumDetail(@PathVariable Long id, @RequestParam(required = false) Long userId) {
        return Results.success(albumService.getAlbumDetail(id,userId));
    }
    @GetMapping
    public Result<PageResp<AlbumBaseResp>> getAlbums(AlbumReq params) {
        return Results.success(albumService.getAlbums(params));
    }

    @GetMapping("/artist/{artistId}")
    public Result<PageResp<AlbumBaseResp>> getArtistAlbum(@PathVariable Long artistId,@RequestParam(required = false) Long userId,@RequestParam(defaultValue = "1") Integer page
    ,@RequestParam(defaultValue = "5") Integer limit){
        return Results.success(albumService.getArtistAlbum(artistId,userId,page,limit));
    }
    @GetMapping("query")
    public Object queryInPage(@RequestParam Integer page,@RequestParam Integer limit,@RequestParam String query){
        AlbumReq params = new AlbumReq();
        params.setPage(page);
        params.setLimit(limit);
        return Results.success(albumService.getAlbums(params));
    }
}
